package com.tianxin.workbao.workBao.Activity;

import android.content.Context;
import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.appcompat.content.res.AppCompatResources;
import androidx.appcompat.widget.Toolbar;
import android.util.AttributeSet;
import android.view.View;
import android.widget.Button;

import com.tianxin.workbao.workBao.R;
import com.tianxin.workbao.workBao.common.Constant;
import com.tianxin.workbao.workBao.helper.ApplicationDataHelper;
import com.tianxin.workbao.workBao.utils.common.ToastUtils;

/**
 * Created by hacker on 2017/7/27.
 */

public class AppDataManagerActivity extends BaseActivity implements View.OnClickListener {


    private Button cleanInternalCacheBtn;
    private Button cleanExternalCacheBtn;
    private Button cleanDatabaseByNameBtn;
    private Button clearAllDatabasesBtn;
    private Button clearAllDataBtn;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.app_data_activity);

        initView();
        initEvent();
    }

    @Override
    public View onCreateView(String name, Context context, AttributeSet attrs) {
        return super.onCreateView(name, context, attrs);
    }

    public void initView() {
        mToolbar = findViewById(R.id.toolbar);
        mToolbar.setTitle("应用程系数据管理");
        mToolbar.setNavigationIcon(AppCompatResources.getDrawable(this, R.drawable.ic_action_back_24dp));
        setSupportActionBar(mToolbar);
        cleanInternalCacheBtn = findViewById(R.id.cleanInternalCache);
        cleanExternalCacheBtn = findViewById(R.id.cleanExternalCache);
        cleanDatabaseByNameBtn = findViewById(R.id.cleanDatabaseByName);
        clearAllDatabasesBtn = findViewById(R.id.clearAllDatabases);
        clearAllDataBtn = findViewById(R.id.clearAllData);
    }

    @Override
    public void initData() {

    }

    @Override
    public void initEvent() {
        mToolbar.setNavigationOnClickListener(view -> AppDataManagerActivity.this.finish());
        cleanInternalCacheBtn.setOnClickListener(this);
        cleanExternalCacheBtn.setOnClickListener(this);
        cleanDatabaseByNameBtn.setOnClickListener(this);
        clearAllDatabasesBtn.setOnClickListener(this);
        clearAllDataBtn.setOnClickListener(this);
    }

    @Override
    public void bindView() {

    }

    @Override
    public void onClick(View view) {
        String message = "清除成功！";
        String failureMessage = "清除失败！";
        ToastUtils.showShort("清除中...");
        switch (view.getId()) {
            case R.id.cleanInternalCache:
                ApplicationDataHelper.cleanInternalCache(this);
                ToastUtils.showLong(message);
                break;
            case R.id.cleanExternalCache:
                ApplicationDataHelper.cleanExternalCache(this);
                ToastUtils.showLong(message);
                break;
            case R.id.cleanDatabaseByName:
                ApplicationDataHelper.cleanDatabaseByName(this, Constant.DB);
                ToastUtils.showLong(message);
                quitApp();
            break;
            case R.id.clearAllDatabases:
                ApplicationDataHelper.cleanDatabases(this);
                ToastUtils.showLong(message);
                quitApp();
                break;
            case R.id.clearAllData:
                ApplicationDataHelper.clearApplicationData(this);
                ToastUtils.showLong(message);
                quitApp();
            break;
        }
    }

}
